package com.wzy.controller;

import com.wzy.annotation.SystemLog;
import com.wzy.domain.ResponseResult;
import com.wzy.domain.vo.ArticleListVO;
import com.wzy.service.CollectionService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 收藏接口
 *
 * @author wzy
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/collection")
public class CollectionController
{
    private final CollectionService collectionService;

    /**
     * 文章是否收藏
     */
    @GetMapping("/isCollected/{articleId}")
    @SystemLog(basenessName = "文章是否收藏")
    public ResponseResult<Boolean> isCollected(@PathVariable Long articleId)
    {
        return collectionService.isCollected(articleId);
    }

    /**
     * 收藏/取消收藏文章
     */
    @PutMapping("/addOrCancelCollect/{articleId}/{flag}")
    @SystemLog(basenessName = "收藏/取消收藏文章")
    public ResponseResult<Void> addOrCancelCollect(@PathVariable Long articleId,
                                                   @PathVariable String flag)
    {
        return collectionService.addOrCancelCollect(articleId, flag);
    }

    /**
     * 获取收藏文章列表
     */
    @GetMapping("/getCollectList")
    @SystemLog(basenessName = "获取收藏文章列表")
    public ResponseResult<List<ArticleListVO>> getCollectList()
    {
        return collectionService.getCollectList();
    }

}
